package com.tarena.sentinel.study.demo02.service;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.tarena.sentinel.study.demo02.repository.HelloRepo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class HelloService {
    @Autowired
    private HelloRepo helloRepo;
    public String sayHi(String name) {
       String result=null;
       Entry entry=null;
       try{
           entry= SphU.entry("sayHiRepo");
           result=helloRepo.sayHi(name);
       }catch (BlockException e){
           log.info("业务层限流限制了repo调用:",e);
           result="repo层做了限流";
       }finally {
           if (entry!=null){
               entry.exit();
           }
       }
       return result;
    }
}
